unit ULoginCt;

interface

uses UUsuarioCt;

type
  TLoginCt = class(TObject)

    private
      instancia : TLoginCt;
      objUsuarioCt : TUsuarioCt;

    public
      constructor Create;
      destructor Destroy;

      class function obterInstancia : TLoginCt;
      function validarUsuario(login, senha : String) : Boolean;
      function obterControle : TUsuarioCt;

end;

implementation

constructor TLoginCt.Create;
begin
  inherited;
    self.instancia := self.Create;
end;

destructor TLoginCt.Destroy;
begin
    self.instancia.Destroy;
  inherited;
end;

class function TLoginCt.obterInstancia : TLoginCt;
var
  instancia : TLoginCt;
begin
  if (instancia = nil) then
    instancia := TLoginCt.Create;

  result := instancia;
end;

function TLoginCt.validarUsuario(login, senha : String) : Boolean;
begin
  if (self.objUsuarioCt = nil) then
    self.objUsuarioCt := TUsuarioCt.Create;

  try
    result := self.objUsuarioCt.validarUsuario(login, senha); 
  finally
    objUsuarioCt.Destroy;
  end;
end;

function TLoginCt.obterControle : TUsuarioCt;
begin
  result := self.objUsuarioCt;
end;

end.
 